package com.lkh.common;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;

public class IKUtil {

    public static ArrayList<String> fit(String text) throws IOException {
        ArrayList<String> words = new ArrayList<>();

        StringReader stringReader = new StringReader(text);
        IKSegmenter ikSegmenter = new IKSegmenter(stringReader, true);

        Lexeme next = ikSegmenter.next();

        while (next != null) {
            words.add(next.getLexemeText());
            next = ikSegmenter.next();
        }

        return words;
    }
}
